<?php
/**
 * Created by PhpStorm.
 * User: leaf
 * Date: 2016/11/23
 * Time: 11:56
 * function:用于将yg_goods(商品表)中cost_price(成本价)中数据同步到yg_order_goods(订单商品表)中的cost_price(成本价)
 */

$ip = "120.76.200.79";
$username = "yunguotest";
$pwd = "yunguotest";
$data_name = "yunguotest";
$con = @mysql_connect($ip,$username,$pwd);
if (!$con)
{
    die('Could not connect: ' . @mysql_error());
}

@mysql_select_db($data_name);




$sql = "select g.cost_price,og.goods_id,og.id from yg_order_goods as og right join yg_goods as g on g.id = og.goods_id ";

$result = @mysql_query($sql,$con);
while($row=@mysql_fetch_assoc($result))
{
    $data[] = $row;
}

foreach($data as $k=>$v){
    $sqls = "update yg_order_goods set cost_price={$v['cost_price']} where id={$v['id']}";
    $res = @mysql_query($sqls,$con);
}



